package com.example.admin.midtermpro41;

import android.content.Context;
import android.util.Log;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/*这个实现模糊搜索功能*/
public class searchFunction {
    public static String[] queryHero(String input){
        ArrayList<String> nameList=new ArrayList<>();
        String[] heroNameList={//匹配中文
                "安琪拉","百里守约","百里玄策","扁鹊","不知火舞","蔡文姬",
                "曹操","成吉思汗","程咬金","达摩","大乔","狄仁杰","典韦",
                "貂蝉","东皇太一"
        };
        String[] heroPingyinList={//匹配拼音
                "anqila","bailishouyue","bailixuance","bianque","buzhihuowu",
                "caiwenji","caocao","chengjisihan","chengyaojin","damo","daqiao",
                "direnjie","dianwei","diaochan","donghuangtaiyi"
        };
        Pattern pattern=Pattern.compile(input);
        for(int i=0;i<heroNameList.length;i++){
            Matcher matcher=pattern.matcher(heroNameList[i]);
            Matcher pingyinMatcher=pattern.matcher(heroPingyinList[i]);
            if(matcher.find()||pingyinMatcher.find()){
                nameList.add(heroNameList[i]);
            }
        }
        return nameList.toArray(new String[nameList.size()]);
    }

}
